<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/2
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <div class="jarviswidget well" id="wid-id-3"
             data-widget-colorbutton="false"
             data-widget-editbutton="false"
             data-widget-togglebutton="false"
             data-widget-deletebutton="false"
             data-widget-fullscreenbutton="false"
             data-widget-custombutton="false"
             data-widget-sortable="false">
            <!-- widget div-->
            <div>
                <div class="widget-body">
                    <a class="btn btn-default" id="btn-re-proattend" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply-all"></i>考勤设置列表
                    </a>
                    <a class="btn btn-default pull-right pull-right-fix" id="btn-save-proattend" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存</a>
                    <hr class="simple">

                    <form id="proAttend" class="smart-form" action="" method="post">
                        <input type="hidden" name="keyId" id="keyId" value="<s:property value="proAttend.id" />"/>
                        <input type="hidden" name="proInfoId" id="proInfoId" value="<s:property value="proInfoId" />"/>

                        <fieldset>
                            <%--<div class="row">--%>
                                <%--<label class="label col col-2">--%>
                                    <%--序号--%>
                                <%--</label>--%>
                                <%--<section class="col col-5">--%>
                                    <%--<label class="input">--%>
                                        <%--<input type="text" name="no" id="no" value="<s:property value="proAttend.no"/>" disabled>--%>
                                    <%--</label>--%>
                                <%--</section>--%>
                            <%--</div>--%>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    正常考勤时间区间
                                </label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input  class="hasDatepicker form-control" name="regularStart" id="regularStart" placeholder="请选择正常考勤开始时间"
                                                type="text" value="<s:date name="regularStartDate" format="yyyy-MM-dd HH:mm"  />">
                                    </label>
                                </section>
                                <label class="label col col-1" style="text-align: center"> ---- </label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input  class="hasDatepicker form-control" name="regularEnd" id="regularEnd" placeholder="请选择正常考勤结束时间"
                                                type="text" value="<s:date name="regularEndDate" format="yyyy-MM-dd HH:mm"  />">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    异常考勤时间区间
                                </label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input  class="hasDatepicker form-control" name="unRegularStart" id="unRegularStart" placeholder="请选择异常考勤开始时间"
                                                type="text" value="<s:date name="unRegularStartDate" format="yyyy-MM-dd HH:mm" />">
                                    </label>
                                </section>
                                <label class="label col col-1" style="text-align: center"> ---- </label>
                                <section class="col col-2">
                                    <label class="input">
                                        <i class="icon-append fa fa-calendar"></i>
                                        <input  class="hasDatepicker form-control" name="unRegularEnd" id="unRegularEnd" placeholder="请选择异常考勤结束时间"
                                                type="text" value="<s:date name="unRegularEndDate" format="yyyy-MM-dd HH:mm" />">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    备注
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="mark" id="mark" placeholder="请输入备注"
                                               type="text" value="<s:property value="proAttend.mark"/>">
                                    </label>
                                </section>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </article>
</div>

<script>

    //返回视图
    $("#btn-re-proattend").click(function(){
        loadURL("ajax-pro-attend!view.action?proInfoId="+$("#proInfoId").val(),$('div#s2'));
    });
    //校验
    $.validator.methods.compareDate = function(value, element, param) {
        var startDate = jQuery(param).val();
        var date1 = new Date(Date.parse(startDate.replace("-", "/")));
        var date2 = new Date(Date.parse(value.replace("-", "/")));
        return date1 < date2;
    };

    $.validator.methods.comparePeriod = function(value, element, param) {
        var rs = $("#regularStart").val();
        var re = $("#regularEnd").val();
        var urs = $("#unRegularStart").val();
        var ure = $("#unRegularEnd").val();
        rs = rs.split(" ")[1];
        re = re.split(" ")[1];
        urs = urs.split(" ")[1];
        ure = ure.split(" ")[1];
        if(urs<rs && ure>rs){
            return false;
        }
        if(urs>rs && urs<=re){
            return false;
        }
        return true;
    };

    $("form#proAttend").validate({
        rules : {
            regularStart : {
                required : true
            },
            regularEnd:{
                required : true,
                compareDate: "#regularStart"
            },
            unRegularStart:{
                required : true
            },
            unRegularEnd:{
                required : true,
                compareDate: "#unRegularStart",
                comparePeriod:"#unRegularStart"
            }
        },
        messages : {
            regularStart : {
                required : '请选择正常考勤开始时间'
            },
            regularEnd : {
                required : '请选择正常考勤结束时间',
                compareDate: "正常考勤结束时间不能早于正常考勤开始时间"
            },
            unRegularStart : {
                required : '请选择异常考勤开始时间'
            },
            unRegularEnd : {
                required : '请选择异常考勤结束时间',
                compareDate: "异常考勤结束时间不能早于异常考勤开始时间",
                comparePeriod: "异常考勤时间不能和正常考勤时间重复"
            }
        },
        errorPlacement : function(error, element) {
            error.insertAfter(element.parent());
        }
    });

    $('.hasDatepicker').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        language: 'zh-CN',
        startView:1,
        minView:0
    });

    $("#regularStart,#regularEnd,#unRegularStart,#unRegularEnd").change(function(e) {
        var rs = $("#regularStart").val();
        if(rs.length==0) return false;
        var re = $("#regularEnd").val();
        if(re.length==0) return false;
        var urs = $("#unRegularStart").val();
        if(urs.length==0) return false;
        var ure = $("#unRegularEnd").val();
        if(ure.length==0) return false;

        var $valid = $("form#proAttend").valid();
        //console.debug($valid);
        if(!$valid){
            return false;
        }
    });
    //保存
    $("#btn-save-proattend").click(function(e) {
                var $valid = $("form#proAttend").valid();
                //console.debug($valid);
                if(!$valid){
                    return false;
                }
                $.SmartMessageBox({
                    title : "提示：",
                    content : "确定提交吗？",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "取消") {
                        e.preventDefault();
                        e.stopPropagation();
                        return;
                    }
                    if (ButtonPressed === "确认") {
                        var rs = $("#regularStart").val();
                        var re = $("#regularEnd").val();
                        var urs = $("#unRegularStart").val();
                        var ure = $("#unRegularEnd").val();
                        rs = rs.split(" ")[1];
                        re = re.split(" ")[1];
                        urs = urs.split(" ")[1];
                        ure = ure.split(" ")[1];
                        $("#regularStart").val(rs);
                        $("#regularEnd").val(re);
                        $("#unRegularStart").val(urs);
                        $("#unRegularEnd").val(ure);
                        $("#btn-save-proattend").attr("disabled", "disabled");
                        form_save("proAttend","<%=path%>/com/ajax-pro-attend!save.action");
                        loadURL("ajax-pro-attend!view.action?proInfoId="+$("#proInfoId").val(),$('div#s2'));
                    }
                });
            }
    );
</script>
<script type="text/javascript">

    $(function(){

    });

</script>
